<?php

namespace App\Http\Controllers\Estate;

use App\Http\Controllers\Controller;
use App\Services\EstateService;
use Illuminate\Http\Request;
use App\Services\UserService;
use Illuminate\Support\Facades\Hash;

class LoginController extends Controller
{
    public function login(UserService $user_service)
    {
        $info = $user_service->login('username', 'estate');

        return $info['status'] ? $this->success($info['data']) : $this->error($info['msg']);
    }

    // 检测是否登陆
    public function check_login(UserService $user_service)
    {
        $info = $user_service->checkLogin('estate', true);
        return $info['status'] ? $this->success($info['data']) : $this->error($info['msg']);
    }

    // 退出账号
    public function logout()
    {
        try {
            auth('estate')->logout();
        } catch (\Exception $e) {
            return $this->success([], __('base.success'));
        }
        return $this->success([], __('base.success'));
    }
    // 物业 注册
    public function register(EstateService $estateService): array
    {
        $estate_service = new EstateService();
//        dd(request());
        $rs = $estate_service->register('username', 'estate');
        return $rs['status'] ? $this->success($rs['data'], $rs['msg']) : $this->error($rs['msg']);
    }
}
